<?php
$this->headLink()->appendStylesheet($this->baseUrl() . '/public/styles/colorbox/colorbox.css');
$this->headScript()->prependFile($this->baseUrl() . '/public/scripts/colorbox/jquery.colorbox-min.js');
$current_user = $auth = Zend_Auth::getInstance();
?>
<article class="module width_full">
    <header><h3>Editar Solicitud</h3></header>
    <div class="module_content">
        <form style="width: 600px;" class="cmxform" method="post" id="solicitudAddForm" action="<?php echo $this->url(); ?>">
            <p>
                <label for="nombre" style="float: left">Para:</label>
                <label ><?php echo $this->user->nombre.' '.$this->user->apellidos; ?></label>
                <input name="id_user" id="id_user" type="hidden" value="<?php echo $this->user->id ?>"/>
            </p>
            <p>
                <label for="subject">Asunto</label>
                <input name="subject" readonly="true" id="subject" type="text" size="58" value="<?php echo $this->solicitud->subject; ?>"/>
            </p>
            <p>
                <label for="detail">Detalle</label>
                <textarea name="detail" id="detail" cols="50" rows="20"><?php echo date("F j, Y, g:i a").' '; ?><?php echo $current_user->getIdentity()->nombre.' '.$current_user->getIdentity()->apellidos.' dice: '; ?> 


<?php echo $this->solicitud->detail; ?></textarea>
            </p>
            <p>
                <label for="detail">Adjuntos</label>
                <a class='inline' href="#inline_content">Subir Archivos</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>Archivos maximo 5 Megabytes</span>
            </p>

            <input name="code_solicitud" id="code_solicitud" type="hidden" value="<?php echo $this->solicitud->code_solicitud ?>"/>

            <div id="result-attachment">
                <?php if ($this->attachments != null): ?>
                    <?php foreach ($this->attachments as $attach): ?>
                        <a href="<?php echo $this->baseUrl() ?>/solicitud/adjuntos/download-attachment/id/<?php echo $attach->id ?>">
                            <img width="16" src="<?php echo $this->baseUrl() ?>/public/styles/admin/images/icon_files/_<?php echo $attach->extension; ?>.png"/>
                            <?php echo $attach->name_original; ?>
                        </a>
                    <?php endforeach; ?>
                <?php endif; ?>
            </div>

            <div class="clear"></div>

            <div class="submit_link">
                <input type="submit" value="Enviar" class="alt_btn"/>
            </div>
        </form>
    </div>

    <!-- This contains the hidden content for inline calls -->
    <div style='display:none'>
        <div id='inline_content' style='padding:10px; background:#fff;'>
            <?php echo $this->partial('solicitud/upload.phtml', 'solicitud', array('code' => $this->solicitud->code_solicitud)); ?>
        </div>
    </div>

    <footer></footer>
</article>
<script language="javascript">
    $().ready(function() {
        
        $(document).on("click", "a.delAttach", function(){ 
            idAttach = $(this).attr('rel');
            $.ajax({
                type: "GET",
                url: "<?php echo $this->baseUrl() ?>/solicitud/adjuntos/borrar-adjunto/id/"+idAttach,
                success: function( strData ){
                    $('#attachment_'+idAttach).remove();
                }
            });
        });
       
        // modal colorbox 
        $(".inline").colorbox({
            inline:true, 
            width:"480px"
        });
        
        $("#solicitudAddForm").validate({
            rules: {
                list_user: "required",
                subject: "required",
                detail: "required"  
            },
            messages: {
                list_user: "Agregre un destinatario.",
                subject: "Agregue un titulo.",
                detail: "Ingrese el detalle."
            }
        });
    } );
</script>
